package com.newlink.building.common_base.utils

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import com.newlink.building.common_base.R

/**
 * Created by xiaodong on 2022/9/15.
 */
class Base_CustomImageToast {
    private var toast: Toast? = null
    private var mImage: ImageView? = null
    private var mMessage: TextView? = null

    constructor(context: Context?, message: String) : this(
        context,
        message,
        R.drawable.toast_success_gray,
        Toast.LENGTH_SHORT
    )

    constructor(context: Context?, message: String, drawableId: Int, duration: Int) {
        toast = Toast(context)
        toast?.duration = duration
        val view = LayoutInflater.from(context).inflate(R.layout.toast_image_custom, null)
        mMessage = view.findViewById(R.id.tv_message)
        mMessage?.text = message
        mImage = view.findViewById(R.id.iv_success)
        mImage?.setBackgroundResource(drawableId)
        toast?.view = view
        toast?.setGravity(Gravity.CENTER, 0, 0)
    }

    fun show() {
        toast?.show()
    }
}